package com.flc.archive.config;

import com.flc.gateway.utils.PropertyFactory;

/**
 * @author haizi
 * @date 2018/1/2
 */
public class AppConfig {

    public RocketMqCfg getRocketMqCfg() {
        return rocketMqCfg;
    }

    private RocketMqCfg rocketMqCfg;

    public class RocketMqCfg {

        public String getGroupName() {
            return groupName;
        }

        public String getNameServerAddr() {
            return nameServerAddr;
        }

        public String getDiagnosisTopic() {
            return diagnosisTopic;
        }

        public String getLoginTopic() {
            return loginTopic;
        }

        public String getReportTopic() {
            return reportTopic;
        }

        public String getCmdTopic() {
            return cmdTopic;
        }

        public String getTrajectoryTopic() {
            return trajectoryTopic;
        }

        String groupName;
        String nameServerAddr;
        String diagnosisTopic;
        String loginTopic;
        String reportTopic;
        String trajectoryTopic;
        String cmdTopic;

    }

    public FileCfg getFileCfg() {
        return fileCfg;
    }

    private FileCfg fileCfg;

    public class FileCfg {

        public int getFlushNum() {
            return flushNum;
        }

        public String getDiagnosisPath() {
            return diagnosisPath;
        }

        public String getReportPath() {
            return reportPath;
        }

        public String getTrajectoryPath() {
            return trajectoryPath;
        }

        public String getChangeFileTimeEveryday() {
            return changeFileTimeEveryday;
        }

        int flushNum;
        String diagnosisPath;
        String reportPath;
        String trajectoryPath;
        String changeFileTimeEveryday;

    }

    public HdfsCfg getHdfsCfg() {
        return hdfsCfg;
    }

    private HdfsCfg hdfsCfg;

    public class HdfsCfg {
        public String getHdfsAddress() {
            return hdfsAddress;
        }

        public String getDiagnosisHdfsPath() {
            return diagnosisHdfsPath;
        }

        public String getReportHdfsPath() {
            return reportHdfsPath;
        }

        public String getTrajectoryHdfsPath() {
            return trajectoryHdfsPath;
        }

        String hdfsAddress;
        String diagnosisHdfsPath;
        String reportHdfsPath;
        String trajectoryHdfsPath;
    }

    private AppConfig() {
        String propfileName = "Archive.properties";

        PropertyFactory factory = new PropertyFactory(propfileName);
        rocketMqCfg = new RocketMqCfg();
        fileCfg = new FileCfg();
        hdfsCfg = new HdfsCfg();

        rocketMqCfg.groupName = factory.getValue("ROCKETMQ.GROUPNAME");
        rocketMqCfg.nameServerAddr = factory.getValue("ROCKETMQ.NAMESERVERADDR");
        rocketMqCfg.diagnosisTopic = factory.getValue("ROCKETMQ.TOPIC.DIAGNOSIS");
        rocketMqCfg.loginTopic = factory.getValue("ROCKETMQ.TOPIC.LOGIN");
        rocketMqCfg.reportTopic = factory.getValue("ROCKETMQ.TOPIC.REPORT");
        rocketMqCfg.trajectoryTopic = factory.getValue("ROCKETMQ.TOPIC.TRAJECTORY");
        rocketMqCfg.cmdTopic = factory.getValue("ROCKETMQ.TOPIC.CMD");

        fileCfg.flushNum = Integer.parseInt(factory.getValue("ARCHIVE.FILE.FLUSHNUM"));
        fileCfg.diagnosisPath = factory.getValue("ARCHIVE.FILE.PATH.DIAGNOSIS");
        fileCfg.reportPath = factory.getValue("ARCHIVE.FILE.PATH.REPORT");
        fileCfg.trajectoryPath = factory.getValue("ARCHIVE.FILE.PATH.TRAJECTORY");
        fileCfg.changeFileTimeEveryday = factory.getValue("ARCHIVE.FILE.CHANGETIME");

        hdfsCfg.hdfsAddress = factory.getValue("ARCHIVE.HDFS.ADDRESS");
        hdfsCfg.diagnosisHdfsPath = factory.getValue("ARCHIVE.HDFS.PATH.DIAGNOSIS");
        hdfsCfg.reportHdfsPath = factory.getValue("ARCHIVE.HDFS.PATH.REPORT");
        hdfsCfg.trajectoryHdfsPath = factory.getValue("ARCHIVE.HDFS.PATH.TRAJECTORY");

    }


    private static volatile AppConfig instance;

    public static AppConfig getInstance() {
        if (instance == null) {
            synchronized(AppConfig.class) {
                if (instance == null) {
                    instance = new AppConfig();
                }
            }
        }
        return instance;
    }


    public static void main(String[] args) {
        RocketMqCfg rocketMqCfg = AppConfig.getInstance().getRocketMqCfg();
        System.out.println(rocketMqCfg.getNameServerAddr());

        FileCfg fileCfg = AppConfig.getInstance().getFileCfg();
        System.out.println(fileCfg.getFlushNum());
        System.out.println(fileCfg.getTrajectoryPath());

    }
}
